{extend name="../../base/view/layout" /}
{block name="my_body"}
<div class="widgetbox box-inverse">
    <div class="widgetcontent wc1">

        <form id="form1" class="stdform" enctype="multipart/form-data" method="post" action="<?php echo url('shop/Goods/add');?>">

            <div class="tabbable">
                <ul class="nav nav-tabs buttons-icons">
                    <li class="active"><a data-toggle="tab" href="#shop_info">基本信息</a></li>
                    <li><a data-toggle="tab" href="#shop_attr">商品属性</a></li>
                    <li><a data-toggle="tab" href="#shop_photos">商品相册</a></li>
                    <li><a data-toggle="tab" href="#shop_content">商品详情</a></li>
                    <li><a data-toggle="tab" href="#shop_desc">其他描述</a></li>
                </ul>
                <div class="tab-content">
                    <div id="shop_info" class="tab-pane active">

                        <div class="par control-group">
                            <label class="control-label" for="shop_id">店铺</label>
                            <span class="field">
                            <select name="shop_id" class="uniformselect" id="shop_id">
                                <?php foreach($shopData as $v):?>
                            	<option value="<?php echo $v['id'];?>"><?php echo $v['title'];?></option>
                                <?php endforeach;?>
                            </select>
                            </span>
                        </div>

                        <div class="par control-group">
                            <label class="control-label" for="goods_name">商品名称</label>
                            <div class="controls"><input type="text" name="goods_name" id="goods_name" class="input-xlarge" /></div>
                        </div>

                        <div class="par control-group">
                            <label class="control-label" for="goods_sn">商品货号</label>
                            <div class="controls"><input type="text" name="goods_sn" id="goods_sn" class="input-xlarge" /></div>
                        </div>

                        <div class="par control-group">
                            <label class="control-label" >配送属性</label>
                            <div class="controls">
                                <input type="radio" name="ps_attr" value="1"  checked="checked" />发货
                                <input type="radio" name="ps_attr" value="2" />不发货
                            </div>
                        </div>


                        <div class="par control-group ps_attr">
                            <label class="control-label" for="sheng_id">商品位置</label>
                            <span class="field">
                            <select name="sheng_id" class="uniformselect" id="sheng_id">
                            	<option value="">--请选择省份--</option>
                                <?php foreach($cityData as $k=>$v):?>
                                 <option value="<?php echo $v['id'];?>"><?php echo $v['name'];?></option>
                                <?php endforeach;?>
                            </select>
                            </span>
                        </div>

                        <div class="par control-group ps_attr">
                            <label class="control-label" for="shi_id"></label>
                            <span class="field">
                            <select name="shi_id" class="uniformselect" id="shi_id">
                            	<option value="">--请选择市--</option>
                            </select>
                            </span>
                        </div>

                        <div class="par control-group ps_attr">
                            <label class="control-label" for="xian_id"></label>
                            <span class="field">
                            <select name="xian_id" class="uniformselect" id="xian_id">
                            	<option value="">--请选择区/县--</option>
                            </select>
                            </span>
                        </div>

                        <div class="par control-group ps_attr">
                            <label class="control-label" for="coordinate">商品坐标位置</label>
                            <div class="controls"><input type="text" name="coordinate" id="coordinate" class="input-xlarge" />&ensp;<a href="http://api.map.baidu.com/lbsapi/getpoint/index.html" target="_blank">选择坐标</a></div>
                        </div>

                        <div class="par control-group">
                            <label class="control-label" for="psfs_id">配送方式</label>
                            <span class="field">
                            <select name="psfs_id" class="uniformselect" id="psfs_id">
                            	<option value="0">包邮</option>
                            </select>
                            </span>
                        </div>

                        <div class="par control-group">
                            <label class="control-label" for="brand_id">品牌</label>
                            <span class="field">
                            <select name="brand_id" class="uniformselect" id="brand_id">
                            	<option value="">--请选择--</option>
                                <?php foreach($brandData as $v):?>
                                <option value="<?php echo $v['id'];?>"><?php echo $v['name'];?></option>
                                <?php endforeach;?>
                            </select>
                            </span>
                        </div>

                        <div class="par control-group">
                            <label class="control-label" for="cat_id">分类</label>
                            <span class="field">
                            <select name="cat_id" class="uniformselect" id="cat_id">
                            	<option value="">--请选择--</option>
                                <?php foreach($catData as $v):?>
                                <option value="<?php echo $v['id'];?>"><?php echo str_repeat('-',$v['level']),$v['name'];?></option>
                                <?php endforeach;?>
                            </select>
                            </span>
                        </div>


                        <div class="par control-group">
                            <label class="control-label" for="promote_start_date">促销开始</label>
                            <div class="controls"><input type="text" name="promote_start_date" id="promote_start_date" class="input-xlarge" /></div>
                        </div>

                        <div class="par control-group">
                            <label class="control-label" for="promote_end_date">促销结束</label>
                            <div class="controls"><input type="text" name="promote_end_date" id="promote_end_date" class="input-xlarge" /></div>
                        </div>

                        <div class="par control-group">
                            <label class="control-label" >是否新品</label>
                            <div class="controls">
                                <input type="radio" name="is_new" value="1"   />是
                                <input type="radio" name="is_new" value="0" checked="checked" />否
                            </div>
                        </div>

                        <div class="par control-group">
                            <label class="control-label" >是否热卖</label>
                            <div class="controls">
                                <input type="radio" name="is_hot" value="1"   />是
                                <input type="radio" name="is_hot" value="0" checked="checked" />否
                            </div>
                        </div>

                        <div class="par control-group">
                            <label class="control-label" >是否精品</label>
                            <div class="controls">
                                <input type="radio" name="is_best" value="1"   />是
                                <input type="radio" name="is_best" value="0" checked="checked" />否
                            </div>
                        </div>

                        <div class="par control-group">
                            <label class="control-label" >是否推荐</label>
                            <div class="controls">
                                <input type="radio" name="is_floor" value="1"   />是
                                <input type="radio" name="is_floor" value="0" checked="checked" />否
                            </div>
                        </div>

                        <div class="par control-group">
                            <label class="control-label" >是否特价</label>
                            <div class="controls">
                                <input type="radio" name="is_discount" value="1" checked="checked"  />是
                                <input type="radio" name="is_discount" value="0"  />否
                                <span class="font-red">&ensp;&ensp;提示:特价商品没有会员价</span>
                            </div>
                        </div>

                        <div class="par control-group">
                            <label class="control-label" >是否自动上架</label>
                            <div class="controls">
                                <input type="radio" name="is_on_sale" value="1" checked="checked"  />是
                                <input type="radio" name="is_on_sale" value="0"  />否
                                <span class="font-red">&ensp;&ensp;提示:审核完成自动上架</span>
                            </div>
                        </div>

                        <div class="par control-group">
                            <label class="control-label" for="sort_num">排序</label>
                            <div class="controls"><input type="text" name="sort_num" id="sort_num" class="input-xlarge" value="100" /></div>
                        </div>

                        <div class="control-group par">
                            <label class="control-label" for="logo">商品主图</label>
                            <div class="controls"><input type="file" name="logo" id="logo" class="input-xlarge"  /></div>
                        </div>

                    </div><!--tab-pane-->


                    <!--属性-->
                    <div id="shop_attr" class="tab-pane">
                        <div class="par control-group">
                            <label class="control-label" >商品属性</label>
                            <span class="field">
                            <select name="type_id" class="uniformselect" id="type_id">
                                <?php foreach($typeData as $v):?>
                                <option value="<?php echo $v['id'];?>" <?php if($v['id'] == '1') echo 'selected';?> ><?php echo $v['name'];?></option>
                                <?php endforeach;?>
                            </select>

                            <div>
                                <ul id='attr_list'>
                                    <li class="li-deltype">默认:<select name="attr_value[1][]"><option value="默认">默认</option></select></li>
                                </ul>
                            </div>
                            </span>
                        </div>


                    </div>

                    <!--相册-->
                    <div id="shop_photos" class="tab-pane">

                        <div class="control-group par">
                            <!--<label class="control-label" for="logo">商品相册</label>-->
                            <div class="controls">
                                <ul>
                                    <li class="li-deltype"><input type="file" name="pic[]"  />&ensp;&ensp;&ensp;&ensp;<input type="button"  value='增加' class="btn btn-primary btn-rounded addpic" /></li>
                                </ul>
                            </div>
                        </div>


                    </div>

                    <!--商品详情-->
                    <div id="shop_content" class="tab-pane">

                        <textarea id="goods_desc" name="goods_desc" ></textarea>

                    </div>

                    <!--其他描述-->
                    <div id="shop_desc" class="tab-pane">

                        <div class="control-group par">
                            <!--<input type="button"  value='增加' desccount = '0' class="btn btn-primary btn-rounded adddesc" style="border:0px;" />-->
                            <div class="controls">
                                <ul class="desc_all">
                                    <li class="li-deltype">
                                        <div class="par control-group">
                                            <!--<label class="control-label" >描述名称</label>-->
                                            <div class="controls">描述名称:
                                                <input type="text" name="desc_name[]"  class="input-xlarge" />
                                                <input type="button" onclick="deldesc(this)" value='删除' class="btn btn-primary btn-rounded " />
                                            </div>
                                        </div>
                                        <textarea id="desc_content0" name="desc_content[]" ></textarea>
                                    </li>
                                    <li class="li-deltype">
                                        <div class="par control-group">
                                            <!--<label class="control-label" >描述名称</label>-->
                                            <div class="controls">描述名称:
                                                <input type="text" name="desc_name[]"  class="input-xlarge" />
                                                <input type="button" onclick="deldesc(this)" value='删除' class="btn btn-primary btn-rounded " />
                                            </div>
                                        </div>
                                        <textarea id="desc_content1" name="desc_content[]" ></textarea>
                                    </li>
                                    <li class="li-deltype">
                                        <div class="par control-group">
                                            <!--<label class="control-label" >描述名称</label>-->
                                            <div class="controls">描述名称:
                                                <input type="text" name="desc_name[]"  class="input-xlarge" />
                                                <input type="button" onclick="deldesc(this)" value='删除' class="btn btn-primary btn-rounded " />
                                            </div>
                                        </div>
                                        <textarea id="desc_content2" name="desc_content[]" ></textarea>
                                    </li>
                                    <li class="li-deltype">
                                        <div class="par control-group">
                                            <!--<label class="control-label" >描述名称</label>-->
                                            <div class="controls">描述名称:
                                                <input type="text" name="desc_name[]"  class="input-xlarge" />
                                                <input type="button" onclick="deldesc(this)" value='删除' class="btn btn-primary btn-rounded " />
                                            </div>
                                        </div>
                                        <textarea id="desc_content3" name="desc_content[]" ></textarea>
                                    </li>
                                    <li class="li-deltype">
                                        <div class="par control-group">
                                            <!--<label class="control-label" >描述名称</label>-->
                                            <div class="controls">描述名称:
                                                <input type="text" name="desc_name[]"  class="input-xlarge" />
                                                <input type="button" onclick="deldesc(this)" value='删除' class="btn btn-primary btn-rounded " />
                                            </div>
                                        </div>
                                        <textarea id="desc_content4" name="desc_content[]" ></textarea>
                                    </li>
                                    <li class="li-deltype">
                                        <div class="par control-group">
                                            <!--<label class="control-label" >描述名称</label>-->
                                            <div class="controls">描述名称:
                                                <input type="text" name="desc_name[]"  class="input-xlarge" />
                                                <input type="button" onclick="deldesc(this)" value='删除' class="btn btn-primary btn-rounded " />
                                            </div>
                                        </div>
                                        <textarea id="desc_content5" name="desc_content[]" ></textarea>
                                    </li>
                                </ul>
                            </div>
                        </div>


                    </div>

                </div><!--tabcontent-->
            </div><!--tabbable-->


            <p class="stdformbutton">
                <input type="submit" class="btn btn-primary" />
            </p>
        </form>
    </div><!--widgetcontent-->
</div><!--widget-->
{/block}

{block name="my_js"}
<script>
    var $ = jQuery.noConflict();
</script>
<script type="text/javascript" src="/qiniu_ueditor_1.4.3/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="/qiniu_ueditor_1.4.3/ueditor.all.js"></script>
<script>
    //    添加描述
//    $('.adddesc').click(function(){
//        var desccount = $(this).attr('desccount');
//        var current_count = Number(desccount) + 1;
//        $(this).attr('desccount',current_count);
//        var html = '<li class="li-deltype"><div class="par control-group"><label class="control-label" >描述名称</label><div class="controls"> <input type="text" name="desc_name[]"  class="input-xlarge" /> <input type="button" onclick="deldesc(this)" value="删除" class="btn btn-primary btn-rounded " /> </div> </div> <textarea id="desc_content'+current_count+'" name="desc_content[]" ></textarea> </li>';
//        $(html).appendTo('.desc_all');
//    });

    UE.getEditor('goods_desc', {
        initialFrameWidth : "100%",
        initialFrameHeight : "500"
    });
    UE.getEditor('desc_content0', {
        initialFrameWidth : "100%",
        initialFrameHeight : "200"
    });
    UE.getEditor('desc_content1', {
        initialFrameWidth : "100%",
        initialFrameHeight : "200"
    });
    UE.getEditor('desc_content2', {
        initialFrameWidth : "100%",
        initialFrameHeight : "200"
    });
    UE.getEditor('desc_content3', {
        initialFrameWidth : "100%",
        initialFrameHeight : "200"
    });
    UE.getEditor('desc_content4', {
        initialFrameWidth : "100%",
        initialFrameHeight : "200"
    });
    UE.getEditor('desc_content5', {
        initialFrameWidth : "100%",
        initialFrameHeight : "200"
    });


    //删除描述
function deldesc(a)
{
    $(a).parent().parent().parent().remove();
}
</script>
<link href="/datetimepicker/jquery-ui-1.9.2.custom.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" charset="utf-8" src="/datetimepicker/jquery-ui-1.9.2.custom.min.js"></script>
<script type="text/javascript" charset="utf-8" src="/datetimepicker/datepicker-zh_cn.js"></script>
<link rel="stylesheet" media="all" type="text/css" href="/datetimepicker/time/jquery-ui-timepicker-addon.min.css" />
<script type="text/javascript" src="/datetimepicker/time/jquery-ui-timepicker-addon.min.js"></script>
<script type="text/javascript" src="/datetimepicker/time/i18n/jquery-ui-timepicker-addon-i18n.min.js"></script>
<script>

    // 添加时间插件
    $.timepicker.setDefaults($.timepicker.regional['zh-CN']);  // 设置使用中文

    $("#promote_start_date").datetimepicker();
    $("#promote_end_date").datetimepicker();


    //<!--AJAX请求商品属性-->
    $("select[name='type_id']").change(function(){
        var type_id=$(this).val();
        var url = "<?php echo url('/base/Common/ajaxGetTypeAttr');?>";
        if(type_id>0){
            $.ajax({
                type:'GET',
                url:url+"?type_id="+type_id,
                dataType:'json',
                success:function(data){
                    var li='';
                    $('#attr_list').find('li').remove();
                    $(data).each(function(k,v){
                        li +="<li class='li-deltype'>";
                        if(v.attr_type=='可选'){
                            li +="<a href='#' onclick='addAttrBtn(this);'>[+]</a>";
                            li +=v.attr_name+":";
                            li +="<select name='attr_value["+v.id+"][]'>";
                            li +="<option value='请选择'>请选择</option>";
                            var attr_values=v.attr_option_values.split(',');
                            for(var i=0; i<attr_values.length;i++){
                                li +="<option value='"+attr_values[i]+"'>"+attr_values[i]+"</option>";
                            }
                            li +="</select>";
                        }else{
                            li +=v.attr_name+":";
                            li +="<input name='attr_value["+v.id+"][]' value='"+v.attr_option_values+"' />";
                        }
                    })
                    $('#attr_list').append(li);
                }
            })
        }
    });
    //增加属性
    function addAttrBtn(a){
        //先获取当前点击的按钮的value,判断是加好还是减号
        var li=$(a).parent();
        if($(a).text()=='[+]'){
            var newLi=li.clone();
            newLi.find("a").text('[-]');
            li.after(newLi);
        }else{
            li.remove();
        }
    }
    //增加图片
    $('.addpic').click(function(){
        var li=$(this).parent();
        if($(this).attr('value')=='增加'){
            var newLi=li.clone(true);
            newLi.find("input[type='button']").attr('value','删除').css('background-color','#ffae00');
            li.after(newLi);
        }else{
            li.remove();
        }
    })

</script>
<script>

    //地区三级联动
    //市
    $('#sheng_id').change(function(){
        var id=$(this).val();
        var url = "<?php echo url('base/City/getCityById');?>";
        $.ajax({
            url:url+'?id='+id,
            type:"GET",
            dataType:"json",
            success:function(data){
                var option="<option value=''>--请选择--</option>";
                $(data).each(function(k,v){
                    option +="<option value='"+v.id+"'>";
                    option +=v.name;
                    option +="</option>";
                })
                $('#shi_id').empty();
                $('#shi_id').append(option);
            }
        });
    });
    //区
    $('#shi_id').change(function(){
        var id=$(this).val();
        var url = "<?php echo url('base/City/getCityById');?>";
        $.ajax({
            url:url+'?id='+id,
            type:"GET",
            dataType:"json",
            success:function(data){
                var option="<option value=''>--请选择--</option>";
                $(data).each(function(k,v){
                    option +="<option value='"+v.id+"'>";
                    option +=v.name;
                    option +="</option>";
                })
                $('#xian_id').empty();
                $('#xian_id').append(option);
            }
        });
    });

    //商品位置
    $(".ps_attr").hide();
    $("input[name='ps_attr']").change(function(){
        var val = $(this).val();
        if(val == 2){
            $(".ps_attr").show();
        } else {
            $(".ps_attr").hide();
        }
    })
</script>
{/block}